﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace LAN_Party_Manager
{
    public partial class frmAll : Form
    {
        public frmAll()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            frmAdd dialog = new frmAdd();
            if (dialog.ShowDialog(this) == DialogResult.OK)
                updateList();
            dialog.Dispose();

        }

        private void frmAll_Load(object sender, EventArgs e)
        {
            updateList();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                foreach (Player t in Player.players)
                {
                    if (t.getName() == lstAll.GetItemText(lstAll.SelectedItem))
                    {
                        Player.players.Remove(t);
                        break;
                    }
                }
                lstAll.Items.Remove(lstAll.SelectedItem);
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void updateList()
        {
            lstAll.Items.Clear();
            if (Player.players.Count > 0)
                foreach (Player p in Player.players)
                {
                    lstAll.Items.Add(p.getName());
                }
        }
    }
}
